<template>
  <div>
    <el-table
      :data="tableData"
      stripe
      style="width: 100%"
      showSummary
      :summaryMethod="getTotal"
    >

      <el-table-column type="index" label="序号" width="50"></el-table-column>
      <el-table-column prop="hash.username" label="责任人" width="120"></el-table-column>
      <el-table-column prop="hash.carid" label="车辆编号" width="180"></el-table-column>
      <el-table-column prop="hash.carno" label="号牌" width="120"></el-table-column>

      <el-table-column prop="hash.cartype" label="车型" width="200">
      </el-table-column>
      <el-table-column prop="hash.repairfee" label="维修保养费" width="120"></el-table-column>
      <el-table-column prop="hash.serverfee" label="车务费用" width="180"></el-table-column>
      <el-table-column prop="hash.oilfee" label="油费" width="180"></el-table-column>

    </el-table>

  </div>
</template>

<script>
export default {
  data() {
    return {
      dialogImageUrl: '',
      dialogVisible2: false,
      dialogVisible: false,
      ts: this.newStore(),
      moneystatus: '',

    };
  },
  props: {
    tableData: {
      type: Array,
      required: true,
    },
    pagobj: {
      type: Object,
      required: true,
    },
  },
  methods: {
    handleCurrentChange() {
      this.$parent.getlist();
    },
    dochange(row) {
      console.log(row, '111111111');

      const req = {
        handle: 'E0E144082D7A10B2DC400B628CBD4AE86FD3EDA6633389D14E476815EFEAD4D1D47247C170B661DC',
        moneystatus: row.hash.moneystatus,
        capitalid: row.hash.capitalid,
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        // this[arrname] = ts.d.data.operation1;
        // console.log(ts.d.data.operation1,'支付方式')
      });
    },
    opendiag(item) {
      this.$parent.opendiag(item);
    },
    getTotal(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计';
          return;
        }
        console.log(column.property);
        if (column.property == 'hash.repairfee') {
          const values = data.map(item => Number(item.hash.repairfee));

          console.log(data);
          console.log(values);

          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            }
            return prev;
          }, 0);
        } else if (column.property == 'hash.serverfee') {
          const values = data.map(item => Number(item.hash.serverfee));

          console.log(data);
          console.log(values);

          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            }
            return prev;
          }, 0);
        } else if (column.property == 'hash.oilfee') {
          const values = data.map(item => Number(item.hash.oilfee));

          console.log(data);
          console.log(values);

          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            }
            return prev;
          }, 0);
        } else {
          sums[index] = '--';
        }
      });

      return sums;
    },
  },
};
</script>

<style>
.cell {
  text-align: center;
}
</style>
